// pages/task/task.js
import ajax from "../../utils/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerList: ['https://file.yledanpei.com/2021/09/24/2b9740fb-2466-4951-b75c-2511b2acc79a.png'],
    marqueeList: [],
    userInfo: null
  },
  /**
   * 获取通知消息列表
   */
  async getMarqueeList() {
    const res = await ajax.get('/wx/marquee/list?type=3');
    this.setData({ marqueeList: res.rows })
  },
  async getUserInfo() {
    const res = await ajax.getUserInfo()
    this.setData({ userInfo: res })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMarqueeList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 朋友圈分享
   */
  onShareTimeline: function () {
    const shareId = this.data.userInfo?.id || ''
    return {
      title: this.data.datas.gName,
      query: `shareId=${shareId}`,
      imageUrl: imageUrl
    }
  },

  /**
   * 用户点击右上角分享
   * type 0企业分享 1园区分享 2合伙人分享
   */
  onShareAppMessage: function (event) {
    const type = event.target.dataset.type
    const { id, nickName } = this.data.userInfo
    let url = '', title = '', imageUrl = ''
    if (type == 0) {
      imageUrl = 'https://file.yledanpei.com/2021/09/23/414e36f2-8d60-4829-bfce-9b47d1a95ebd.png'
      title = `${nickName}-邀请您企业入驻`
      url = '/pagesEnterprise/pages/enterpriseAuthentication/enterpriseAuthentication'
    } else if (type == 1) {
      imageUrl = 'https://file.yledanpei.com/2021/09/23/6816582a-5403-4f36-8615-179edc479b3f.png'
      title = `${nickName}-邀请您园区入驻`
      url = "/pagesEnterprise/pages/parkSign/parkSign"
    } else if (type == 2) {
      imageUrl = 'https://file.yledanpei.com/2021/09/23/464ef731-d92b-47f6-ba59-668a9172527d.png'
      title = `${nickName}-邀请您加盟合伙人`
      url = "/pagesMine/pages/cityPartner/cityPartner"
    }
    return {
      title, imageUrl, path: `${url}?shareId=${id}`
    }
  }
})